package com.work.work.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.work.work.dto.ProjectResourceDetailDTO;
import com.work.work.entity.Resource;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ResourceMapper extends BaseMapper<Resource> {
    @Select("SELECT r.* FROM t_resource r " +
            "INNER JOIN t_project_resource pr ON r.id = pr.resource_id " +
            "WHERE pr.project_id = #{projectId}")
    Page<Resource> selectResourcesByProjectId(Integer projectId, Page<Resource> page);
    @Select("SELECT " +
            "p.id as project_id, " +
            "p.project_name, " +
            "p.start_time, " +
            "p.end_time, " +
            "p.description, " +
            "p.status, " +
            "p.team_id " +
            "FROM t_project p " +
            "WHERE p.id = #{projectId}")
    ProjectResourceDetailDTO getProjectDetail(Integer projectId);

    @Select("SELECT " +
            "r.id as resource_id, " +
            "r.resource_name, " +
            "r.resource_type, " +
            "pr.allocated_quantity, " +
            "r.unit " +
            "FROM t_project_resource pr " +
            "JOIN t_resource r ON pr.resource_id = r.id " +
            "WHERE pr.project_id = #{projectId}")
    List<ProjectResourceDetailDTO.ResourceUsage> getProjectResources(Integer projectId);

}